package com.zhsj.OkeHomeConsumption.ui.activity.wallet;

import android.Manifest;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.OkeHomeConsumptionApi;
import com.zhsj.OkeHomeConsumption.empty.FormalUserInfo;
import com.zhsj.OkeHomeConsumption.network.HttpClient;
import com.zhsj.OkeHomeConsumption.network.JsonResponseHandler;
import com.zhsj.OkeHomeConsumption.other.TimeChecker;
import com.zhsj.OkeHomeConsumption.other.URLEntity;
import com.zhsj.OkeHomeConsumption.ui.activity.wallet.packerview.ActionSheet;
import com.zhsj.OkeHomeConsumption.utils.JsonUtils;
import com.zhsj.OkeHomeConsumption.utils.LogUtils;
import com.zhsj.OkeHomeConsumption.utils.PermissionFail;
import com.zhsj.OkeHomeConsumption.utils.PermissionSuccess;
import com.zhsj.OkeHomeConsumption.utils.PermissionUtil;
import com.zhsj.OkeHomeConsumption.utils.SignUtil;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import me.lxz.photopicker.camera.Mode;
import me.lxz.photopicker.camera.OnPhotoPickFinsh;
import me.lxz.photopicker.camera.PictureSelector;
import me.lxz.photopicker.tools.SimpleImageLoader;
import okhttp3.MediaType;

/**
 * Created by zwj on 2017/10/15.
 * 开通钱包--上传身份证照片
 */

public class OpenWalletIDImageFragment extends BaseFragment implements View.OnClickListener, ActionSheet.ActionSheetListener{

    /**
     * 实例化ProgressDrawableAlertDialog
     */
    private ProgressDrawableAlertDialog pDialogUtils = null;
    /**
     * 计时器
     */
    private TimeChecker timeChecker = null;
    //左标提
    private TextView topbar_textview_leftitle;
    //标题
    private TextView topbar_textview_title;

    //正面
    private ImageView idcard_positive;
    private String idcard_positiveStr;
    //反面
    private ImageView idcard_reverse;
    private String idcard_reverseStr;
    //营业执照
    private LinearLayout business_license_linear;
    private ImageView business_license_image;
    private String business_licenseStr;
    //组织机构代码
    private LinearLayout enterprise_org_code_linear;
    private ImageView enterprise_org_code_image;
    private String enterprise_org_codeStr;
    //银行许可证
    private LinearLayout bank_openlicense_linear;
    private ImageView bank_openlicense_image;
    private String bank_openlicenseStr;
    //开通钱包
    private TextView open_wallet_text;

    private final int PER_CAMERA = 3;
    //选择正反面 1正面   0反面  2营业执照  3组织机构代码  4银行许可证
    private int isPositive = 1;

    //识别身份 1个人  2企业
    private int isUse = 1;
    //是否是企业钱包--有值是企业  空是个人
    private String type_register;

    private FormalUserInfo userInfo;

    public static OpenWalletIDImageFragment newInstance(String type_register, FormalUserInfo userInfo) {
        
        Bundle args = new Bundle();
        
        OpenWalletIDImageFragment fragment = new OpenWalletIDImageFragment();
        args.putSerializable("userInfo",userInfo);
        args.putString("type_register", type_register);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        userInfo = (FormalUserInfo) getArguments().getSerializable("userInfo");
        type_register = getArguments().getString("type_register");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_openwallet_idimage, container, false);
        initView(view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initListener();
        judgmentIdentity();
    }
    private void initView(View view){
        topbar_textview_leftitle = (TextView) view.findViewById(R.id.topbar_textview_leftitle);
        topbar_textview_leftitle.setVisibility(View.VISIBLE);
        topbar_textview_title = (TextView) view.findViewById(R.id.topbar_textview_title);
        topbar_textview_title.setText("开通钱包");
        idcard_positive = (ImageView) view.findViewById(R.id.idcard_positive);
        idcard_reverse = (ImageView) view.findViewById(R.id.idcard_reverse);
        open_wallet_text = (TextView) view.findViewById(R.id.open_wallet_text);
        business_license_image = (ImageView) view.findViewById(R.id.business_license_image);
        business_license_linear = (LinearLayout) view.findViewById(R.id.business_license_linear);
        enterprise_org_code_linear = (LinearLayout) view.findViewById(R.id.enterprise_org_code_linear);
        enterprise_org_code_image = (ImageView) view.findViewById(R.id.enterprise_org_code_image);
        bank_openlicense_linear = (LinearLayout) view.findViewById(R.id.bank_openlicense_linear);
        bank_openlicense_image = (ImageView) view.findViewById(R.id.bank_openlicense_image);
    }

    private void initListener(){
        timeChecker = new TimeChecker(TimeOutHandler.timeOutHandler, Constants.TIME_OUT);
        pDialogUtils = new ProgressDrawableAlertDialog(getActivity());
        topbar_textview_leftitle.setOnClickListener(this);
        idcard_positive.setOnClickListener(this);
        idcard_reverse.setOnClickListener(this);
        open_wallet_text.setOnClickListener(this);
        business_license_image.setOnClickListener(this);
        enterprise_org_code_image.setOnClickListener(this);
        bank_openlicense_image.setOnClickListener(this);
    }
    /**
     * 判断身份
     */
    private void judgmentIdentity(){
        if (userInfo != null){

                //个人身份
                business_license_linear.setVisibility(View.GONE);
                enterprise_org_code_linear.setVisibility(View.GONE);
                bank_openlicense_linear.setVisibility(View.GONE);
                isUse = 1;
        }
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.topbar_textview_leftitle:
                _mActivity.onBackPressed();
                break;
            case R.id.idcard_positive:
                //正面
                isPositive = 1;
                PermissionUtil.needPermission(this, PER_CAMERA, new String[]{Manifest.permission.CAMERA,
                        Manifest.permission.READ_EXTERNAL_STORAGE});
                break;
            case R.id.idcard_reverse:
                //背面
                isPositive = 0;
                PermissionUtil.needPermission(this, PER_CAMERA, new String[]{Manifest.permission.CAMERA,
                        Manifest.permission.READ_EXTERNAL_STORAGE});
                break;
            case R.id.business_license_image:
                //营业执照
                isPositive = 2;
                PermissionUtil.needPermission(this, PER_CAMERA, new String[]{Manifest.permission.CAMERA,
                        Manifest.permission.READ_EXTERNAL_STORAGE});
                break;
            case R.id.enterprise_org_code_image:
                //组织机构代码
                isPositive = 3;
                PermissionUtil.needPermission(this, PER_CAMERA, new String[]{Manifest.permission.CAMERA,
                        Manifest.permission.READ_EXTERNAL_STORAGE});
                break;
            case R.id.bank_openlicense_image:
                //银行开户许可证
                isPositive = 4;
                PermissionUtil.needPermission(this, PER_CAMERA, new String[]{Manifest.permission.CAMERA,
                        Manifest.permission.READ_EXTERNAL_STORAGE});
                break;
            case R.id.open_wallet_text:
                //开通钱包
                if (TextUtils.isEmpty(idcard_positiveStr)){
                    showShortToast("请上传身份证正面照片");
                    return;
                }
                if (TextUtils.isEmpty(idcard_reverseStr)){
                    showShortToast("请上传身份证背面照片");
                    return;
                }
                if (isUse == 2) {
                    if (TextUtils.isEmpty(business_licenseStr)) {
                        showShortToast("请上传营业执照");
                        return;
                    }
                    if (TextUtils.isEmpty(enterprise_org_codeStr)) {
                        showShortToast("请上传组织机构代码");
                        return;
                    }
                    if (TextUtils.isEmpty(bank_openlicenseStr)) {
                        showShortToast("请上传银行许可证");
                        return;
                    }
                    openWalletEnterprise("RSA",userInfo.getId() + "", idcard_positiveStr, idcard_reverseStr, business_licenseStr, enterprise_org_codeStr, bank_openlicenseStr);
                }else {
                    realName("RSA", userInfo.getId() + "", "2", SubmitCaseContent());
                }

                break;
        }
    }

    private List<HashMap<String, String>> hashMapLists;
    /**
     * 风控参数
     * @return
     */
    public String SubmitCaseContent() {
        //设置日期格式
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String content = "";
        if (hashMapLists == null)
            hashMapLists = new ArrayList<>();
        if (hashMapLists.size() > 0)
            hashMapLists.clear();

        HashMap<String, String> map = new HashMap<>();
        map.put("user_info_dt_register",df.format(new Date()));

        hashMapLists.add(map);

        if (hashMapLists == null) {
            return "";
        }
        StringBuilder mStringBuilder = new StringBuilder();

        for (int i = 0; i < hashMapLists.size(); i++) {
            String hashMapToJson = JsonUtils.hashMapToJson(hashMapLists.get(i));
            mStringBuilder.append(hashMapToJson).append(",");
        }
        if (mStringBuilder.length() > 0) {
            String substring = mStringBuilder.toString().substring(0, mStringBuilder.toString().lastIndexOf(","));
            content = substring;
        } else {

        }
        return content;
    }

    /**
     * 实名认证
     * @param sign_type  RSA
     * @param user_id 用户id
     * @param check_auth 用户认证状态 2
     * @param risk_item 风险控制参数
     */
    public void realName(String sign_type, String user_id, String check_auth, String risk_item) {
        // post传参使用的HashMap
        HashMap<String, String> paramMaps = new HashMap<String, String>();
        // 生成sign值所使用的HashMap
        HashMap<String, String> mSendCodeHashMap = new HashMap<String, String>();
//        mSendCodeHashMap.put("token", Constants.TOKEN);
        mSendCodeHashMap.put("v", Constants.APPVERSION);
        mSendCodeHashMap.put("t", Constants.TIME);
        mSendCodeHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mSendCodeHashMap.put("platform", Constants.PLAFORM);
        mSendCodeHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mSendCodeHashMap.put("client", Constants.CLIENT);
        mSendCodeHashMap.put("sign_type", sign_type);
        mSendCodeHashMap.put("user_id", user_id);
        mSendCodeHashMap.put("check_auth", check_auth);
        mSendCodeHashMap.put("risk_item", risk_item);


        LogUtils.e("mSendCodeHashMap", mSendCodeHashMap.toString());
        //post 传参
        paramMaps.put("sign_type", sign_type);
        paramMaps.put("user_id", user_id);
        paramMaps.put("check_auth", check_auth);
        paramMaps.put("risk_item", risk_item);

        // 网络计时器及线程
        TimeOutHandler.pDialogUtils = pDialogUtils;
        pDialogUtils.show();
        timeChecker.start();
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mSendCodeHashMap);
        LogUtils.e("mSendCodeHashMap", SignUtil.getInstance().getSign(mSendCodeHashMap));
        HttpClient.post(OkeHomeConsumptionApi.REAL_NAME_AUTHENTICATION, paramMaps, new JsonResponseHandler() {

            @Override
            public void onSuccess(int statusCode, String content) {
                // TODO Auto-generated method stub
                super.onSuccess(statusCode, content);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                try {
                    LogUtils.e("content_实名认证", "content=" + content);
                    JSONTokener jsonT = new JSONTokener(content);
                    JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
                    String code = jsonOBJ.optString("code");
                    String message = jsonOBJ.optString("message");
                    if (code.equals("N000000")) {
                        // 数据对接正常
                        JSONObject jsonObject = jsonOBJ.optJSONObject("data");
                        JSONObject data = jsonObject.optJSONObject("data");
                        String ret_msg = data.optString("ret_msg");
                        String ret_code = data.optString("ret_code");
                        if ("0000".equals(ret_code)) {
                            openWallet("RSA",userInfo.getId() + "", idcard_positiveStr, idcard_reverseStr);
                        }else {
                            showShortToast(ret_msg + "");
                        }
                    } else if (code.equals(Constants.STATUSTOKENERROR)) {
                        if (!message.equals("null")) {
                            showShortToast(message);
                        }
                    } else {
                        if (!message.equals("null")) {
                            showShortToast(message);
                        }
                    }
                } catch (Exception ex) {
                    LogUtils.e("DresserPartnerRegisterPost", "失败 ");
                }
            }

            @Override
            public void onFailure(Throwable e) {
                // TODO Auto-generated method stub
                super.onFailure(e);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                LogUtils.e("onFailure", "" + e.toString());
            }
        });
    }

    /**
     *  企业身份
     * @param sign_type RSA
     * @param user_id
     * @param front_card 正面
     * @param back_card 背面
     * @param copy_license 营业执照
     * @param copy_org 组织机构代码
     * @param bank_openlicense 银行开户许可证
     */
    public void openWalletEnterprise(String sign_type, String user_id, String front_card, String back_card, String copy_license, String copy_org, String bank_openlicense) {
        // post传参使用的HashMap
        HashMap<String, String> paramMaps = new HashMap<String, String>();
        // 生成sign值所使用的HashMap
        HashMap<String, String> mSendCodeHashMap = new HashMap<String, String>();
//        mSendCodeHashMap.put("token", Constants.TOKEN);
        mSendCodeHashMap.put("v", Constants.APPVERSION);
        mSendCodeHashMap.put("t", Constants.TIME);
        mSendCodeHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mSendCodeHashMap.put("platform", Constants.PLAFORM);
        mSendCodeHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mSendCodeHashMap.put("client", Constants.CLIENT);
        mSendCodeHashMap.put("sign_type", sign_type);
        mSendCodeHashMap.put("user_id", user_id);
        mSendCodeHashMap.put("front_card", front_card);
        mSendCodeHashMap.put("back_card", back_card);
        mSendCodeHashMap.put("copy_license", copy_license);
        mSendCodeHashMap.put("copy_org", copy_org);
        mSendCodeHashMap.put("bank_openlicense", bank_openlicense);


        LogUtils.e("mSendCodeHashMap", mSendCodeHashMap.toString());
        //post 传参
        paramMaps.put("sign_type", sign_type);
        paramMaps.put("user_id", user_id);
        paramMaps.put("front_card", front_card);
        paramMaps.put("back_card", back_card);
        paramMaps.put("copy_license", copy_license);
        paramMaps.put("copy_org", copy_org);
        paramMaps.put("bank_openlicense", bank_openlicense);

        // 网络计时器及线程
        TimeOutHandler.pDialogUtils = pDialogUtils;
        pDialogUtils.show();
        timeChecker.start();
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mSendCodeHashMap);
        LogUtils.e("mSendCodeHashMap", SignUtil.getInstance().getSign(mSendCodeHashMap));
        HttpClient.post(OkeHomeConsumptionApi.WALLET_USERPHOTO_ENTERPRISE_ISOK, paramMaps, new JsonResponseHandler() {

            @Override
            public void onSuccess(int statusCode, String content) {
                // TODO Auto-generated method stub
                super.onSuccess(statusCode, content);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                try {
                    LogUtils.e("content_验证身份证照片", "content=" + content);
                    JSONTokener jsonT = new JSONTokener(content);
                    JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
                    String code = jsonOBJ.optString("code");
                    String message = jsonOBJ.optString("message");
                    if (code.equals("N000000")) {
                        // 数据对接正常
                        JSONObject jsonObject = jsonOBJ.optJSONObject("data");
                        JSONObject data = jsonObject.optJSONObject("data");
                        String ret_msg = data.optString("ret_msg");
                        String ret_code = data.optString("ret_code");
                        if ("0000".equals(ret_code)) {
                            setFragmentResult(RESULT_OK, new Bundle());
                            _mActivity.onBackPressed();
                        }else {
                            showShortToast(ret_msg + "");
                        }
                    } else if (code.equals(Constants.STATUSTOKENERROR)) {
                        if (!message.equals("null")) {
                            showShortToast(message);
                        }
                    } else {
                        if (!message.equals("null")) {
                            showShortToast(message);
                        }
                    }
                } catch (Exception ex) {
                    LogUtils.e("DresserPartnerRegisterPost", "失败 ");
                }
            }

            @Override
            public void onFailure(Throwable e) {
                // TODO Auto-generated method stub
                super.onFailure(e);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                LogUtils.e("onFailure", "" + e.toString());
            }
        });
    }

    /**
     *  个人身份
     * @param sign_type RSA
     * @param user_id
     * @param front_card 正面
     * @param back_card 背面
     */
    public void openWallet(String sign_type, String user_id, String front_card, String back_card) {
        // post传参使用的HashMap
        HashMap<String, String> paramMaps = new HashMap<String, String>();
        // 生成sign值所使用的HashMap
        HashMap<String, String> mSendCodeHashMap = new HashMap<String, String>();
//        mSendCodeHashMap.put("token", Constants.TOKEN);
        mSendCodeHashMap.put("v", Constants.APPVERSION);
        mSendCodeHashMap.put("t", Constants.TIME);
        mSendCodeHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mSendCodeHashMap.put("platform", Constants.PLAFORM);
        mSendCodeHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mSendCodeHashMap.put("client", Constants.CLIENT);
        mSendCodeHashMap.put("sign_type", sign_type);
        mSendCodeHashMap.put("user_id", user_id);
        mSendCodeHashMap.put("front_card", front_card);
        mSendCodeHashMap.put("back_card", back_card);


        LogUtils.e("mSendCodeHashMap", mSendCodeHashMap.toString());
        //post 传参
        paramMaps.put("sign_type", sign_type);
        paramMaps.put("user_id", user_id);
        paramMaps.put("front_card", front_card);
        paramMaps.put("back_card", back_card);

        // 网络计时器及线程
        TimeOutHandler.pDialogUtils = pDialogUtils;
        pDialogUtils.show();
        timeChecker.start();
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mSendCodeHashMap);
        LogUtils.e("mSendCodeHashMap", SignUtil.getInstance().getSign(mSendCodeHashMap));
        HttpClient.post(OkeHomeConsumptionApi.WALLET_USERPHOTO_ISOK, paramMaps, new JsonResponseHandler() {

            @Override
            public void onSuccess(int statusCode, String content) {
                // TODO Auto-generated method stub
                super.onSuccess(statusCode, content);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                try {
                    LogUtils.e("content_验证身份证照片", "content=" + content);
                    JSONTokener jsonT = new JSONTokener(content);
                    JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
                    String code = jsonOBJ.optString("code");
                    String message = jsonOBJ.optString("message");
                    if (code.equals("N000000")) {
                        // 数据对接正常
                        JSONObject jsonObject = jsonOBJ.optJSONObject("data");
                        if(jsonObject!=null){
                            JSONObject data = jsonObject.optJSONObject("data");
                            String ret_msg = data.optString("ret_msg");
                            String ret_code = data.optString("ret_code");
                            if ("0000".equals(ret_code)) {
                                setFragmentResult(RESULT_OK, new Bundle());
                                _mActivity.onBackPressed();
                            }else {
                                showShortToast(ret_msg + "");
                            }
                        }else{
                            showShortToast("证件已提交，请等待审核");
                        }

                    } else if (code.equals(Constants.STATUSTOKENERROR)) {
                        if (!message.equals("null")) {
                            showShortToast(message);
                        }
                    } else {
                        if (!message.equals("null")) {
                            showShortToast(message);
                        }
                    }
                } catch (Exception ex) {
                    LogUtils.e("DresserPartnerRegisterPost", "失败 ");
                }
            }

            @Override
            public void onFailure(Throwable e) {
                // TODO Auto-generated method stub
                super.onFailure(e);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                LogUtils.e("onFailure", "" + e.toString());
            }
        });
    }

    @Override
    public void onDismiss(ActionSheet actionSheet, boolean isCancel) {

    }

    @Override
    public void onOtherButtonClick(ActionSheet actionSheet, int index, int viewId) {
        switch (index + 1) {
            case 1:
                    // 去拍照
                    PictureSelector
                            .create(getActivity(), Mode.SYSTEM_CAMERA)
                            .setListen(listen)
                            .start();

                break;
            case 2:
                //单选图片
                PictureSelector
                        .create(getActivity(), Mode.AS_WEIXIN_IMGCAPTRUE)
                        .setListen(listen)
                        .start();
                break;

            default:
                break;
        }
    }

    OnPhotoPickFinsh listen = new OnPhotoPickFinsh() {
        @Override
        public void onPhotoPick(List<File> list) {
            switch (ViewId) {
                case R.id.idcard_positive:
                    upLoadIDCard(list.get(0), ViewId);
                    break;
                case R.id.idcard_reverse:
                    upLoadIDCard(list.get(0), ViewId);
                    break;
                case R.id.business_license_image:
                    upLoadIDCard(list.get(0), ViewId);
                    break;
                case R.id.enterprise_org_code_image:
                    upLoadIDCard(list.get(0), ViewId);
                    break;
                case R.id.bank_openlicense_image:
                    upLoadIDCard(list.get(0), ViewId);
                    break;
                default:
                    break;
            }
        }
    };

    private int ViewId = -1;

    @PermissionSuccess(requestCode = PER_CAMERA)
    private void grantPermissionSuccess() {
        getActivity().setTheme(R.style.ActionSheetStyleiOS7);
        if (isPositive == 1){
            showActionSheet(idcard_positive.getId());
            ViewId = idcard_positive.getId();
        }else if (isPositive == 0){
            showActionSheet(idcard_reverse.getId());
            ViewId = idcard_reverse.getId();
        }else if (isPositive == 2){
            showActionSheet(business_license_image.getId());
            ViewId = business_license_image.getId();
        }else if (isPositive == 3) {
            showActionSheet(enterprise_org_code_image.getId());
            ViewId = enterprise_org_code_image.getId();
        }else if (isPositive == 4) {
            showActionSheet(bank_openlicense_image.getId());
            ViewId = bank_openlicense_image.getId();
        }

    }
    public void showActionSheet(int viewid) {
        ActionSheet.createBuilder(getActivity(), getFragmentManager(), viewid)
                .setCancelButtonTitle("取消")
                .setOtherButtonTitles("去拍照", "去图库")
                .setCancelableOnTouchOutside(true).setListener(this).show();
    }
    @PermissionFail(requestCode = PER_CAMERA)
    private void grantPersmissionFail() {
        showShortToast("照相机权限被拒绝");
    }



    public void upLoadIDCard(final File imgfile, final int ViewId) {
        // 生成sign值所使用的HashMap
        final HashMap<String, String> mLogOnHashMap = new HashMap<String, String>();
        mLogOnHashMap.put("v", Constants.APPVERSION);
        mLogOnHashMap.put("t", Constants.TIME);
        LogUtils.e("ImgMotifyUPload time =", Constants.TIME);
        mLogOnHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mLogOnHashMap.put("platform", Constants.PLAFORM);
        mLogOnHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mLogOnHashMap.put("client", Constants.CLIENT);
        // 网络计时器及线程
        TimeOutHandler.pDialogUtils = pDialogUtils;
        pDialogUtils.show();
        timeChecker.start();
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mLogOnHashMap);
        HttpClient.uploadFile(OkeHomeConsumptionApi.ELVDOU_PHOTOUP, imgfile, MediaType.parse("image/png"), new JsonResponseHandler() {

            @Override
            public void onSuccess(int statusCode, String content) {
                super.onSuccess(statusCode, content);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                LogUtils.e("content_zhaopian", content);
                try {
                    JSONTokener jsonT = new JSONTokener(content);
                    JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
                    String code = jsonOBJ.optString("code");
                    String message = jsonOBJ.optString("message");
                    if (code.equals("N000000")) {
                        JSONObject jsonObject = jsonOBJ.optJSONObject("data");
                        String photoId = jsonObject.optString("photoId");
                        LogUtils.e("photoId", photoId);
                        switch (ViewId) {
                            case R.id.idcard_positive:
                                Glide.with(getActivity()).load(imgfile).placeholder(R.drawable.zhanweitu_bg).into(idcard_positive);
                                idcard_positiveStr = photoId;
                                break;
                            case R.id.idcard_reverse:
                                Glide.with(getActivity()).load(imgfile).placeholder(R.drawable.zhanweitu_bg).into(idcard_reverse);
                                idcard_reverseStr = photoId;
                                break;
                            case R.id.business_license_image:
                                Glide.with(getActivity()).load(imgfile).placeholder(R.drawable.zhanweitu_bg).into(business_license_image);
                                business_licenseStr = photoId;
                                break;
                            case R.id.enterprise_org_code_image:
                                Glide.with(getActivity()).load(imgfile).placeholder(R.drawable.zhanweitu_bg).into(enterprise_org_code_image);
                                enterprise_org_codeStr = photoId;
                                break;
                            case R.id.bank_openlicense_image:
                                Glide.with(getActivity()).load(imgfile).placeholder(R.drawable.zhanweitu_bg).into(bank_openlicense_image);
                                bank_openlicenseStr = photoId;
                                break;
                        }
                    } else if (code.equals(Constants.STATUSTOKENERROR)) {
                        // token过期
                        if (!message.equals("null")) {
                            showShortToast(message);
                        }
                    } else {
                        if (!message.equals("null")) {
                            showShortToast(message);
                        }
                    }
                } catch (JSONException ex) {
                    LogUtils.e("ImgMotifyUPload", "异常 ");
                }
            }

            @Override
            public void onFailure(Throwable e) {
                super.onFailure(e);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                LogUtils.e("onFailure", "" + e.toString());
            }
        });
    }

}
